<%#
 Copyright 2008 Steven Barth <steven@midlink.org>
 Copyright 2008-2012 Jo-Philipp Wich <jow@openwrt.org>
 Licensed to the public under the Apache License 2.0.
-%>
<%
    local ver = require "luci.version"
    local disp = require "luci.dispatcher"
    local request  = disp.context.path
    local i18n = require "luci.i18n"
    local lang = i18n.context.lang
    local fs    = require "nixio.fs"
    local conf  = require "luci.config"
    local uci   = require "uci"
    local cur_lang = uci.get("luci", "main", "lang")

    local i18ndir = i18n.i18ndir .. "base."
    local langs = {}
    for k, v in luci.util.kspairs(conf.languages) do
        local file = i18ndir .. k:gsub("_", "-")
        if k:sub(1, 1) ~= "." and fs.access(file .. ".lmo") then
            langs[#langs +1] = {
            label= v,
            value= k
        }
        end
    end

%>


<!DOCTYPE html>
<html lang="en">
    
<head>
        <title><%:Login%></title>
        <meta charset="UTF-8" />
        <meta name="viewport" content="width=device-width, initial-scale=1.0" />
        <link rel="stylesheet" href="<%=media%>/css/bootstrap.min.css?v=git-18.038.25564-8fe5d3d" />
        <link rel="stylesheet" href="<%=media%>/css/bootstrap-responsive.min.css?v=git-18.038.25564-8fe5d3d" />
        <link rel="stylesheet" href="<%=media%>/css/matrix-login.css?v=git-18.038.25564-8fe5d3d" />
        <link href="<%=media%>/font-awesome/css/font-awesome.css?v=git-18.038.25564-8fe5d3d" rel="stylesheet" />

</head>
    <body  style="background-color: #2b3a50;">
        <div id="loginbox">            
            <form id="loginform" class="form-vertical" method="post"  action="<%=pcdata(luci.http.getenv("REQUEST_URI"))%>">
                <div class="control-group normal_text"> <h3><img src="<%=media%>/img/logo.png" alt="Logo" /></h3><%:Login device%></div>

                <div class="control-group">
                    <div class="controls">
                        <div class="main_input_box">
                            <span class="add-on bg_lg"><i class="icon-user"></i></span><input type="text" placeholder="Username" name="luci_username" value="<%=duser%>" style="
    margin-left: 4px;"/>
                        </div>
                    </div>
                </div>
                <div class="control-group">
                    <div class="controls">
                        <div class="main_input_box">
                            <span class="add-on bg_ly"><i class="icon-lock"></i></span><input type="password" placeholder="Password" name="luci_password" style="
    margin-left: 4px;"/>
                        </div>
                    </div>
                </div>
                <div class="control-group">
                    <div class="controls">
                        <div class="main_input_box">
                            <span class="add-on bg_ls"><i class="icon-globe"></i></span>
                            <select name="luci_lang" style="height:38px;border:0px;display:inline-block;width:77%;line-height:28px;margin-bottom:3px;">
                                <option value="auto" <%if cur_lang == 'auto' then %>selected<%end%>>auto</option>
                                <%- for k,v in pairs(langs) do -%>
                                <option value="<%=v.value%>"<%if cur_lang == v.value then%>selected<%end%>><%=v.label%></option>
                                <%- end -%>
                            </select>
                        </div>
                    </div>
                </div>
                <div class="form-actions">
                    <span class="pull-right"><input type="submit" value="<%:Login%>" class="btn btn-success" /></span>
                </div>
            </form>
            
				<div class="normal_text">
					<%- if fuser then %>
					<div class="error"><%:Invalid username and/or password! Please try again.%></div>
					<br />
					<% end -%>
				</div>
				
                  
           
        </div>
        
<script type="text/javascript">//<![CDATA[
	var input = document.getElementsByName('luci_password')[0];
	if (input)
        input.focus();
//]]></script>

<%
local uci  = require "luci.model.uci".cursor()
local fs  = require "nixio.fs"
local https_key = uci:get("uhttpd", "main", "key")
local https_port = uci:get("uhttpd", "main", "listen_https")
if type(https_port) == "table" then
	https_port = https_port[1]
end

if https_port and fs.access(https_key) then
	https_port = https_port:match("(%d+)$")
%>

<script type="text/javascript">//<![CDATA[
	if (document.location.protocol != 'https:') {
		var url = 'https://' + window.location.hostname + ':' + '<%=https_port%>' + window.location.pathname;
		var img=new Image;
		img.onload=function(){window.location = url};
		img.src='https://' + window.location.hostname + ':' + '<%=https_port%>' + '<%=resource%>/cbi/up.gif?' + Math.random();;
		setTimeout(function(){
			img.src=''
		}, 5000);
	}
//]]></script>

<% end %>

    </body>

</html>



